﻿/*
 * Created by SharpDevelop.
 * User: ratul
 * Date: 3/9/2010
 * Time: 3:02 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;

namespace H264Impl.NET.NAL
{
	/// <summary>
	/// Description of NALUnitFactory.
	/// </summary>
	public static class NALUnitFactory
	{
//		public NALUnitFactory()
//		{
//		}
//		
		public static NALUnit create(BitStream _NALUnitBitStream)
		{
			bool forbiddenZeroBit = _NALUnitBitStream.getBit();
			UInt32 _NALRefID = _NALUnitBitStream.getBits(2);
			UInt32 nalUnitType =  _NALUnitBitStream.getBits(5);
			
			
			switch(nalUnitType)
			{
				case (UInt32)(NALUnit.NALUnitType.CODED_SLICE_OF_NON_IDR_PICTURE):
					return new VCLNALUnit.CodedSliceOfNonIDRPictureVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case (UInt32)(NALUnit.NALUnitType.CODED_SLICE_DATA_PARTITION_A):
					return new VCLNALUnit.CodedSliceDataPartitionA_VCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);	
				case (UInt32)(NALUnit.NALUnitType.CODED_SLICE_DATA_PARTITION_B):
      				return new VCLNALUnit.CodedSliceDataPartitionB_VCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);	
      			case (UInt32)(NALUnit.NALUnitType.CODED_SLICE_DATA_PARTITION_C):
      				return new VCLNALUnit.CodedSliceDataPartitionC_VCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);	
      			case (UInt32)(NALUnit.NALUnitType.CODED_SLICE_OF_IDR_PICTURE):
      				return new VCLNALUnit.CodedSliceOfIDRPictureVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
      			case (UInt32)(NALUnit.NALUnitType.SUPPLEMENTAL_ENHANCEMENT_INFORMATION):
					return new NonVCLNALUnit.SupplementalEnhancementInfoNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case(UInt32)(NALUnit.NALUnitType.SEQUENCE_PARAMETER_SET):
					return new NonVCLNALUnit.SequenceParameterSetNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case (UInt32)(NALUnit.NALUnitType.PICTURE_PARAMETER_SET):
					return new NonVCLNALUnit.PictureParameterSetNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case(UInt32)(NALUnit.NALUnitType.ACCESS_UNIT_DELIMITER):
					return new NonVCLNALUnit.AccessUnitDelimiterNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case (UInt32)(NALUnit.NALUnitType.END_OF_SEQUENCE):
					return new NonVCLNALUnit.EndOfSequenceNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case (UInt32)(NALUnit.NALUnitType.END_OF_STREAM):
					return new NonVCLNALUnit.EndOfStreamNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case(UInt32)(NALUnit.NALUnitType.FILLER_DATA):
					return new NonVCLNALUnit.FillerDataNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case  (UInt32)(NALUnit.NALUnitType.SEQUENCE_PARAMETER_SET_EXTENSION):
					return new NonVCLNALUnit.SequenceParameterSetExtensionNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case (UInt32)(NALUnit.NALUnitType.PREFIX_NAL_UNIT):
					return new NonVCLNALUnit.PrefixNALUnitNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case (UInt32)(NALUnit.NALUnitType.SUBSET_SEQUENCE_PARAMETER_SET):
					return new NonVCLNALUnit.SubsetSequenceParameterSetNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case (UInt32)(NALUnit.NALUnitType.CODED_SLICE_OF_AUXILIARY_CODED_PICTUREWITHOUT_PARTITIONING):
					return new NonVCLNALUnit.CodedSliceOfAuxiliaryCodedPictureWithoutPartitioningNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
				case (UInt32)(NALUnit.NALUnitType.CODED_SLICE_EXTENSION):
					return new NonVCLNALUnit.CodedSliceExtensionNonVCLNALUnit(_NALUnitBitStream, forbiddenZeroBit, _NALRefID);
			}
				
			
			return null;
			
			
		}
	}
}
